function [tasks_, attributes_, batchMethods_] = dXtask(num_objects)
% function [tasks_, attributes_, batchMethods_] = dXtask(num_objects)
%
% Constructor method for class task
%
% Arguments:
%   num_objects   ... number of dXtask objects to create
%
% Returns:
%   tasks_        ... array of created dXtasks
%   attributes_   ... default object attributes
%   batchMethods_ ... 

% Copyright 2005 by Joshua I. Gold
%   University of Pennsylvania


% whip up a struct to show feedback about this task
feedbackSelect = { ...
    'showPctGood',      false; ...
    'showNumGood',      false; ...
    'showGoodRate',     false; ...
    'showPctCorrect',   false; ...
    'showNumCorrect',   false; ...
    'showCorrectRate',  false; ...
    'showTrialCount',   false; ...
    'showMoreFeedback', false};
feedbackSelect = cell2struct(feedbackSelect(:,2), feedbackSelect(:,1), 1);

% default object attributes ... see dXtask/set for details
attributes = { ...
    % name              type		ranges(?)	default
    'name',             'string',   [],         []; ...
    'trialOrder',       'string',   {'block', 'random', 'staircase', 'repeat'}, 'random'; ...
    'timeLimit',        'scalar',   [],         inf; ... % seconds
    'blockReps',        'scalar',   [],         1; ...
    'startTaskFcn',     'cell',     [],         {}; ... % {func [and args]}
    'endTaskFcn',       'cell',     [],         {}; ... % {func [and args]}
    'intertrialFcn',    'cell',     [],         {}; ... % {func [and args]}
    'iti',              'scalar',   [],         []; ... % []=defer to dXparadigm
    'helpers',          'cell',     [],         {}; ...
    'anyStates',        'cell',     [],         {}; ...
    'allStates',        'cell',     [],         {}; ...
    'noStates',         'cell',     [],         {}; ...
    'wrtState',         'string',   [],         []; ...
    'timeout',          'scalar',   [],         60; ... % seconds
    'objectsToFIRA',    'cell',     [],         {'control', 'query'};  ...
    'statesToFIRA',     'cell',     [],         {}; ...
    'ptrsToFIRA',       'cell',     [],         {}; ...
    'bgColor',          'array',    [],         []; ...
    'blankFlag',        'boolean',  [],         false; ... % blank screen after loop?
    'restoreFlag',      'boolean',  [],         false; ... % restore groups after loop?
    'showFeedback',     'boolean',  [],         false; ...
    'feedbackSelect',   'struct',   [],         feedbackSelect; ...
    'moreFeedback',     'string',   [],         []; ...
    'moreFeedbackFunction','string',[],         []; ...
    'requireReset',     'cell',     [],         {'trialOrder', 'blockReps'}; ...
    'userData',         'auto',     [],         []; ... % any data you want
    'isAvailable',      'auto',     [],         true; ...
    'saveToFIRA',       'auto',     [],         {}; ...
    'totalTrials',      'auto',     [],         0; ...
    'startTime',        'auto',     [],         0; ... % GetSecs
    'goodTrials',       'auto',     [],         0; ...
    'correctTrials',    'auto',     [],         0; ...
    'outcome',          'auto',     [],         {}; ...
    'tag',              'auto',     [],         []};

% tags are numeric array, make struct from defaults
ta = cell2struct(attributes(:,4), attributes(:,1), 1);
for i = 1:num_objects
    
    % make the object
    tasks_(i) = class(ta, 'dXtask');
end

% return the attributes, if necessary
if nargout > 1
    attributes_ = attributes;
end

% return list of batch methods
if nargout > 2
    batchMethods_ = {};
end
